package com.hc.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hc.bean.SysRole;
import com.hc.bean.UserRoleResultModel;
import com.hc.entity.SysUserInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author hc
 */
public interface SysUserInfoMapper extends BaseMapper<SysUserInfo> {

    @Select("SELECT\n" +
            "\tt2.* \n" +
            "FROM\n" +
            "\tsys_user_role t1,\n" +
            "\tsys_role t2 \n" +
            "WHERE\n" +
            "\tt1.role_id = t2.role_id\n" +
            "\tand t1.user_id = #{userId}")
    List<SysRole> getUserRole(@Param("userId") String userId);


    @Select("SELECT\n" +
            "\tt1.user_id as userId,\n" +
            "  t3.role_id as roleId,\n" +
            "\tt3.role_name as roleName,\n" +
            "\tt3.role_type as roleType,\n" +
            "\tt3.role_type_id as roleTypeId,\n" +
            "\tt3.f_role_id as fRoleId\n" +
            "FROM\n" +
            "\tsys_userinfo t1\n" +
            "\tLEFT JOIN sys_user_role t2 ON t1.user_id = t2.user_id\n" +
            "\tLEFT JOIN sys_role t3 on t2.role_id = t3.role_id")
    List<SysRole> getAllRoles();
}
